package com.aidex.biz.service.impl;

import com.aidex.biz.domain.JinjianKpi;
import com.aidex.biz.domain.vo.SelfKpiStatisticVo;
import com.aidex.biz.domain.vo.SumKpiStatisticVo;
import com.aidex.biz.mapper.JinjianKpiMapper;
import com.aidex.biz.service.JinjianKpiService;
import com.aidex.common.annotation.DataScope;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.common.utils.NumberUtils;
import com.aidex.common.utils.StringUtils;
import com.aidex.common.utils.sql.SqlUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 员工业绩Service业务层处理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-08-13
 */
@Service
@Transactional(readOnly = true)
public class JinjianKpiServiceImpl extends BaseServiceImpl<JinjianKpiMapper, JinjianKpi> implements JinjianKpiService {
    private static final Logger log = LoggerFactory.getLogger(JinjianKpiServiceImpl.class);

    /**
     * 获取单条数据
     *
     * @param jinjianKpi 员工业绩
     * @return 员工业绩
     */
    @Override
    public JinjianKpi get(JinjianKpi jinjianKpi) {
        JinjianKpi dto = super.get(jinjianKpi);
        return dto;
    }

    /**
     * 获取单条数据
     *
     * @param id 员工业绩id
     * @return 员工业绩
     */
    @Override
    public JinjianKpi get(String id) {
        JinjianKpi dto = super.get(id);
        return dto;
    }


    /**
     * 查询员工业绩列表
     *
     * @param jinjianKpi 员工业绩
     * @return 员工业绩
     */
    @Override
    @DataScope(userAlias = "a", deptAlias = "a")
    public List<JinjianKpi> findList(JinjianKpi jinjianKpi) {
        return super.findList(jinjianKpi);
    }

    /**
     * 分页查询员工业绩列表
     *
     * @param jinjianKpi 员工业绩
     * @return 员工业绩
     */
    @Override
    @DataScope(userAlias = "a", deptAlias = "a")
    public PageInfo<JinjianKpi> findPage(JinjianKpi jinjianKpi) {
        return super.findPage(jinjianKpi);
    }

    /**
     * 保存员工业绩
     *
     * @param jinjianKpi
     * @return 结果
     */
    @Override
    public boolean save(JinjianKpi jinjianKpi) {
        return super.save(jinjianKpi);
    }


    /**
     * 删除员工业绩信息
     *
     * @param jinjianKpi
     * @return 结果
     */
    @Override
    public boolean remove(JinjianKpi jinjianKpi) {
        return super.remove(jinjianKpi);
    }

    /**
     * 批量删除员工业绩
     *
     * @param ids 需要删除的员工业绩ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteJinjianKpiByIds(String[] ids) {
        return mapper.deleteJinjianKpiByIds(ids);
    }

    /**
     * 获取最大编号
     *
     * @param jinjianKpi 员工业绩
     * @return 结果
     */
    @Override
    public int findMaxSort(JinjianKpi jinjianKpi) {
        return NumberUtils.nextOrder(mapper.findMaxSort(jinjianKpi));
    }

    @DataScope(userAlias = "a", deptAlias = "a")
    @Override
    public PageInfo<SelfKpiStatisticVo> getSelfKpiStatisticVo(JinjianKpi jinjianKpi) {
        PageDomain page = jinjianKpi.getPage();
        Integer pageNum = page.getPageNum();
        Integer pageSize = page.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            String orderBy = SqlUtil.escapeOrderBySql(page.getOrderBy());
            Boolean reasonable = page.getReasonable();
            PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
        }
        return new PageInfo(mapper.getSelfKpiStatisticVo(jinjianKpi));
    }

    @DataScope(userAlias = "a", deptAlias = "a")
    @Override
    public SumKpiStatisticVo getSumKpiStatisticVo(JinjianKpi jinjianKpi) {
        return mapper.getSumKpiStatisticVo(jinjianKpi);
    }
}
